package com.rc.evcharger.netty.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 存放桩的地址（在内存中）
 *
 * @author kb
 */
public class NettyPileHandler {
    static Logger logger = LoggerFactory.getLogger(NettyPileHandler.class);
    private static NettyPileHandler nettyPileHandler = null;
    private static Map<String, String> rtuaMap = new HashMap<>();

    public static NettyPileHandler newInstance() {
        if (nettyPileHandler == null) {
            nettyPileHandler = new NettyPileHandler();
        }
        return nettyPileHandler;
    }

    public void add(String rtua, String channelId) {
        rtuaMap.put(rtua, channelId);
    }

    public String get(String rtua) {
        return rtuaMap.get(rtua);
    }

    public void remove(String rtua) {
        rtuaMap.remove(rtua);
    }

    public Map<String, String> getRtuaMap() {
        return rtuaMap;
    }

    public String getRtuaByChannel(String channelId) {
        for (Map.Entry<String, String> entry : rtuaMap.entrySet()) {
            if (entry.getValue().equals(channelId)) {
                return entry.getKey();
            }
        }
        return null;
    }
}
